/*
 * Copyright 2020-2030 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.gitee.minimalismstyle.fresh.common.api

import com.gitee.minimalismstyle.fresh.common.api.config.ApiConst
import com.gitee.minimalismstyle.fresh.common.api.fallback.SysApiFallback
import com.gitee.minimalismstyle.fresh.common.core.domain.R
import com.gitee.minimalismstyle.fresh.common.core.domain.Resource
import com.gitee.minimalismstyle.fresh.common.core.service.ResourceService
import feign.Response
import org.springframework.cloud.openfeign.FeignClient
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.*
import org.springframework.web.multipart.MultipartFile

/**
 *  OSS服务公共api
 * @author maoxiaodong
 */
@FeignClient(value = ApiConst.SERVICE_ID_OSS, path = ApiConst.CTX_OSS, fallback = SysApiFallback::class, primary = false )
interface OssApi {

    /**
     *  保存文件
     * @param file
     * @return
     */
    @PutMapping(value = ["ossFile/upload"], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
    fun upload(@RequestPart("file") file: MultipartFile): R<Map<String, Any>>

    @GetMapping(value = ["oss/file/download/{id}"], consumes = [MediaType.APPLICATION_PROBLEM_JSON_VALUE])
    fun getResponse(@PathVariable("id") id: Long): Response

    /**
     * 根据id删除文件
     * @param id
     * @return
     */
    @DeleteMapping("ossFile/{id}")
    fun deleteById(@PathVariable id: Long): R<Int>
}